from pyecharts.charts import Bar

# bar = Bar()
# bar.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
# bar.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
# # render 会生成本地 HTML 文件，默认会在当前目录生成 render.html 文件
# # 也可以传入路径参数，如 bar.render("mycharts.html")
# bar.render()




bar = Bar()
bar.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
bar.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
# render 会生成本地 HTML 文件，默认会在当前目录生成 render.html 文件
# 也可以传入路径参数，如 bar.render("mycharts.html")
bar.render()


import xlrd, xlwt
import os
import time
import difflib
import json


class ReadExcel(object):
    def __init__(self, data_path, sheetname,):
        #定义一个属性接收文件路径
        self.data_path = data_path
        # 定义一个属性接收工作表名称
        self.sheetname = sheetname
        # 使用xlrd模块打开excel表读取数据
        self.data = xlrd.open_workbook(self.data_path)
        # 根据工作表的名称获取工作表中的内容
        self.table = self.data.sheet_by_name(self.sheetname)
        # 获取工作表的有效行数
        self.rowNum = self.table.nrows

    def getExcelData(self):
        failNum = 0
        chatNum = 0
        noContentNum = 0
        sysErrorNum = 0
        for i in range(1, self.rowNum):
            # 获取单元格数据
            chatVal = self.table.cell_value(i, 1)
            noAns = self.table.cell_value(i, 14)
            annotation = self.table.cell_value(i, 15)   # 备注
            if chatVal == '闲聊':
                chatNum += 1
            if noAns.startswith('很抱歉') or noAns.startswith('抱歉') or noAns.startswith('对不起'):
                failNum += 1
            if chatVal == '闲聊' and not noAns:
                noContentNum += 1
            if annotation.endswith("'系统错误'}"):
                sysErrorNum += 1


        chatNumList.append(chatNum)
        failNumList.append(failNum)
        noContentList.append(noContentNum)
        sysErrorList.append(sysErrorNum)

        print('返回闲聊总次数为{}'.format(chatNum))
        print('返回无效回答次数为{}'.format(failNum))
        print('返回系统报错次数为{}'.format(sysErrorNum))
        print('返回无内容次数为{}'.format(noContentNum))
            # print(data_list)      [[(command,data),(command,data)],[],[],[]，[]]



if __name__ == '__main__':
    data_path = '/Users/v_baiguanghui/Downloads/云控相关项目/101.测试脚本/bigScreenDigitalPeople/result/闲聊/'
    sheetname = '闲聊类指令'
    failNumList = []
    chatNumList = []
    noContentList = []
    sysErrorList = []

    # 获取excel数据
    files_list = os.listdir(data_path)
    for file_name in files_list:
        read_obj = ReadExcel(data_path+file_name, sheetname, )
        read_obj.getExcelData()

    print('闲聊总数',sum(chatNumList))
    print('返回报错次数', sum(sysErrorList))
    print('内容无法回答总次数',sum(failNumList))
    print('无内容总次数',sum(noContentList))








